home *** CD-ROM | disk | FTP | other *** search
- /* CheckIn.c: CheckIn applet for ProjectDrag
- *
- * A set of applets for drag and drop source control by Tim Maroney.
- * See develop, issue 23 for details.
- *
- * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
- * and using the MoreFiles utilities by Jim Luther.
- *
- * This software is free, but don't modify and redistribute it without
- * changing the status window to indicate your name and your changes!
- */
-
-
- #include <Errors.h>
-
- #include "DSUserProcs.h"
- #include "SourceServer.h"
- #include "PDDialogs.h"
- #include "Comments.h"
- #include "TasksAndErrors.h"
-
-
- void CheckInFile(FSSpec *file, Boolean doingFolder);
-
-
- /* This routine is called for each file passed in the ODOC event. */
-
- pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
- {
- #pragma unused ( opening )
- #pragma unused ( userDataHandle )
-
- ProcessFileOrFolder(myFSSPtr, CheckInFile, ProcessFolder);
- PopAllTasks();
- }
-
-
- void CheckInFile(FSSpec *file, Boolean doingFolder)
- {
- Str63 userName;
- Str15 nickname;
- Str255 comment;
- AEDesc command;
- Str255 projectName;
- OSErr err;
- CKIDHandle theCKID;
- short oldLabel;
-
- /* find the user name and initials */
- err = GetUserSettings(userName, nickname, false);
- if (err != noErr)
- {
- gDone = true;
- return;
- }
-
- /* get the CKID */
- TaskStart(2001, 2, file->name, NULL, NULL, NULL); /* inspecting */
- err = ExtractCKID(file, &theCKID);
- TaskDone();
- if (err != noErr)
- {
- /* add new file to project */
-
- TaskStart(2001, 3, file->name, NULL, NULL, NULL); /* adding */
-
- /* confirm the add */
- if (!ResTextYesNo(kProjectDragStrings, kConfirmAddFile, file->name, NULL, NULL, NULL))
- {
- RaiseErrorNumber(userCanceledErr);
- return;
- }
-
- /* mount the project */
- err = MountProjectFromFolder(file->vRefNum, file->parID, projectName);
- if (err != noErr) return;
-
- /* get the checkin comment from the user */
- GetIndString(comment, kProjectDragStrings, kFirstCheckedIn);
- if (!GetChangeComment(true, file->name, comment))
- return;
-
- /* add the "first checked in" change comment and header */
- err = AddFirstTimeHeader(file, userName, nickname, comment);
- if (err != noErr) return;
-
- /* create a CheckIn command for SourceServer
- * CheckIn -new -cs <comment> -project <project> -u <user> <file>
- */
- err = CreateCommand(&command, "CheckIn");
- if (err == noErr)
- err = AddCStringArg(&command, "-new");
- if (err == noErr)
- err = AddCommentArg(&command, comment);
- if (err == noErr)
- err = AddProjectArg(&command, projectName);
- if (err == noErr)
- err = AddUserArg(&command, userName);
- if (err == noErr)
- err = AddFileNameArg(&command, file);
- if (err != noErr)
- {
- AEDisposeDesc(&command);
- RaiseErrorNumber(err);
- return;
- }
- }
- else
- {
- /* Make sure the file is writeable.
- * If the user dragged a folder, don't complain about all the errors!
- * Just check in the ones that are OK to check in.
- */
-
- TaskStart(2001, 1, file->name, NULL, NULL, NULL); /* checking in */
-
- if (!(*theCKID)->writeable && !(*theCKID)->modifyReadOnly)
- {
- DisposeHandle((Handle)theCKID);
- if (!doingFolder)
- RaiseErrorString(kProjectDragStrings, kNoCheckInPermission,
- file->name, NULL, NULL, NULL);
- else
- TaskDone(); /* so the task block gets discarded */
- return;
- }
-
- /* XXX see if the version numbers match; if not, refuse to check in */
-
- /* XXX see if the modification date has changed; if not, put up an alert,
- * and if the user confirms, bump the mod date to avoid an error
- */
-
- /* extract the checkout comment from the CKID */
- {
- StringPtr s = (*theCKID)->projectPath; /* careful -- not locked down */
- s += s[0] + 2; /* skip the project name and null character */
- s += s[0] + 2; /* skip the user name and null character */
- s += s[0] + 2; /* skip the revision number and null character */
- s += s[0] + 2; /* skip the file name and null character */
- if (s[0] == 0) /* seems to put three chars in null string.... */
- s += 3; /* skip the task and null character */
- else
- s += s[0] + 2; /* skip the task and null character */
- BlockMove(s, comment, s[0] + 1); /* copy the comment */
- }
-
- /* add the change comment to the file header */
- err = AddCheckinComment(file, userName, nickname, comment);
- if (err != noErr)
- {
- DisposeHandle((Handle)theCKID);
- return;
- }
-
- /* mount the project */
- err = MountProjectFromCKID(theCKID, projectName);
- DisposeHandle((Handle)theCKID);
- if (err != noErr) return;
-
- /* create a CheckIn command for SourceServer
- * CheckIn -cs <comment> -project <project> -u <user> <file>
- */
- err = CreateCommand(&command, "CheckIn");
- if (err == noErr)
- err = AddCommentArg(&command, comment);
- if (err == noErr)
- err = AddProjectArg(&command, projectName);
- if (err == noErr)
- err = AddUserArg(&command, userName);
- if (err == noErr)
- err = AddFileNameArg(&command, file);
- if (err != noErr)
- {
- AEDisposeDesc(&command);
- RaiseErrorNumber(err);
- return;
- }
- }
-
- /* modify the label to red (6) */
- SetFileLabel(file, 6, &oldLabel);
-
- err = SendCommand(&command); /* send the command to SourceServer */
- if (err == noErr)
- TaskDone();
- else
- SetFileLabel(file, oldLabel, NULL);
- }
-
-
- void DoFileMenu(short itemID)
- {
- if ( itemID == 1 )
- SelectFile(); // call file selection userProc
- else
- SendQuitToSelf(); // send self a 'quit' event
- }
-